package br.ueg.p2.agenda;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {

	public static void main(String[] args) throws Exception{
	    Connection conn = getConnectionApplication();
	    System.out.println("Got Connection.");
		
	    
	    DatabaseMetaData meta = conn.getMetaData();
	    ResultSet rs = meta.getTables(null,null,"cursosView", new String[]{"TABLE", "VIEW"});

	    while (rs.next()) {
	      String tableName = rs.getString("TABLE_NAME");
	      System.out.println("tableName=" + tableName);
	    }
	    
	    conn.close();
	}

	public static Connection getConnectionApplication() throws SQLException {
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			return DriverManager.getConnection("jdbc:sqlserver://AMANDA-PC:1433;databaseName=agenda;user=sa;password=12345;");
		} catch (ClassNotFoundException e) {
			throw new SQLException(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
